<template>
  <div class="dashboard-container">
    <!-- 统计卡片 -->
    <el-row :gutter="20">
      <el-col :span="6" v-for="item in statistics" :key="item.title">
        <el-card shadow="hover" class="statistics-card">
          <div class="card-content">
            <el-icon class="icon" :class="item.type">
              <component :is="item.icon" />
            </el-icon>
            <div class="info">
              <div class="value">{{ item.value }}</div>
              <div class="title">{{ item.title }}</div>
            </div>
          </div>
        </el-card>
      </el-col>
    </el-row>

    <!-- 图表区域 -->
    <el-row :gutter="20" class="chart-row">
      <el-col :span="16">
        <el-card shadow="hover" class="chart-card">
          <template #header>
            <div class="card-header">
              <span>访问统计</span>
              <el-radio-group v-model="timeRange" size="small">
                <el-radio-button label="week">本周</el-radio-button>
                <el-radio-button label="month">本月</el-radio-button>
                <el-radio-button label="year">全年</el-radio-button>
              </el-radio-group>
            </div>
          </template>
          <div class="chart-container">
            图表区域（这里需要集成ECharts）
          </div>
        </el-card>
      </el-col>
      
      <el-col :span="8">
        <el-card shadow="hover" class="chart-card">
          <template #header>
            <div class="card-header">
              <span>快捷操作</span>
            </div>
          </template>
          <div class="quick-actions">
            <el-button type="primary" icon="Plus">添加用户</el-button>
            <el-button type="success" icon="Upload">数据导入</el-button>
            <el-button type="warning" icon="Download">生成报表</el-button>
            <el-button type="info" icon="Setting">系统设置</el-button>
          </div>
        </el-card>
      </el-col>
    </el-row>

    <!-- 最新动态 -->
    <el-card shadow="hover" class="activity-card">
      <template #header>
        <div class="card-header">
          <span>最新动态</span>
          <el-button type="primary" link>查看更多</el-button>
        </div>
      </template>
      <el-timeline>
        <el-timeline-item
          v-for="(activity, index) in activities"
          :key="index"
          :type="activity.type"
          :color="activity.color"
          :timestamp="activity.time"
        >
          {{ activity.content }}
        </el-timeline-item>
      </el-timeline>
    </el-card>
  </div>
</template>

<script setup>
import { ref } from 'vue'
import {
  User,
  Goods,
  ShoppingCart,
  Money,
  Plus,
  Upload,
  Download,
  Setting
} from '@element-plus/icons-vue'

// 统计数据
const statistics = [
  {
    title: '用户总数',
    value: '1,234',
    icon: User,
    type: 'primary'
  },
  {
    title: '商品总数',
    value: '456',
    icon: Goods,
    type: 'success'
  },
  {
    title: '订单总数',
    value: '789',
    icon: ShoppingCart,
    type: 'warning'
  },
  {
    title: '总收入',
    value: '￥123,456',
    icon: Money,
    type: 'danger'
  }
]

// 时间范围选择
const timeRange = ref('week')

// 最新动态
const activities = [
  {
    content: '张三添加了新商品「iPhone 15 Pro」',
    time: '刚刚',
    type: 'primary',
    color: '#409EFF'
  },
  {
    content: '系统自动备份完成',
    time: '5分钟前',
    type: 'success',
    color: '#67C23A'
  },
  {
    content: '李四更新了用户权限配置',
    time: '2小时前',
    type: 'warning',
    color: '#E6A23C'
  },
  {
    content: '系统检测到异常登录',
    time: '1天前',
    type: 'danger',
    color: '#F56C6C'
  }
]
</script>

<style lang="scss" scoped>
.dashboard-container {
  .statistics-card {
    margin-bottom: 20px;
    
    .card-content {
      display: flex;
      align-items: center;
      
      .icon {
        font-size: 48px;
        padding: 10px;
        border-radius: 8px;
        margin-right: 16px;
        
        &.primary {
          background-color: #ecf5ff;
          color: #409eff;
        }
        
        &.success {
          background-color: #f0f9eb;
          color: #67c23a;
        }
        
        &.warning {
          background-color: #fdf6ec;
          color: #e6a23c;
        }
        
        &.danger {
          background-color: #fef0f0;
          color: #f56c6c;
        }
      }
      
      .info {
        .value {
          font-size: 24px;
          font-weight: bold;
          line-height: 1;
          margin-bottom: 8px;
        }
        
        .title {
          font-size: 14px;
          color: #909399;
        }
      }
    }
  }

  .chart-row {
    margin-bottom: 20px;
  }

  .chart-card {
    .card-header {
      display: flex;
      justify-content: space-between;
      align-items: center;
    }
    
    .chart-container {
      height: 350px;
    }
    
    .quick-actions {
      display: grid;
      grid-template-columns: repeat(2, 1fr);
      gap: 16px;
      padding: 16px;
      
      .el-button {
        width: 100%;
      }
    }
  }

  .activity-card {
    .el-timeline {
      padding: 16px;
    }
  }
}
</style>
